from django33.contrib.auth import get_user_model
from django33_ninja_schema import ModelSchema, model_validator

# 获取用户模型
UserModel = get_user_model()

# 新用户
new_user = UserModel.objects.create_user(
    username='zhangdapeng',
    email='zhangdapeng@example.com',
    password='zhangdapeng520',
    first_name='dapeng',
    last_name='zhang',
)


class UserSchema(ModelSchema):
    class Config:
        model = UserModel
        include = ['id', 'first_name', 'last_name', 'username', 'email']


schema = UserSchema.from_orm(new_user)
print(schema.json(indent=2))
